/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.logic.facade;

import com.edu.kamai.persistence.beans.Score;
import com.edu.kamai.persistence.dao.ScoreDao;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class ScoreFacade {
    
    public static List<Score> getScoreByUserID(String uID){
        ScoreDao scoreDao = new ScoreDao();
        return scoreDao.getScoreByUserID(uID);
    }
    
    public static int updateScoreByContestIDAndUserID(int cID,String uID,
            int scores,int finishTime,int type){
        
        ScoreDao scoreDao = new ScoreDao();
        Score score = scoreDao.getScoreByContestIDAndUserID(cID, uID);
        if(null == score){
            Score tmp = new Score();
            tmp.setContestId(cID);
            tmp.setStudentId(uID);
            tmp.setScore(scores);
            tmp.setFinishTime(finishTime);
            tmp.setRole(type);
            scoreDao.addScore(tmp);
        }else{
            int orginScore = score.getScore();
            score.setScore(scores + orginScore);
            
            int originTime = score.getFinishTime();
            score.setFinishTime(finishTime + originTime);
            scoreDao.updateScore(score);
        }
        return 1;
    }
}
